#include <iostream>
#include <vector>
#include <algorithm>
#include <sys/time.h>

using namespace std;

void subsetiter( vector<int>& nums, int subLen,int begin,vector<vector<int> >& res,vector<int> &cur )
{
  if( cur.size() == subLen )
  {
    res.push_back(cur);
  }
  if(begin == nums.size() )
    return;

  for(int i = begin; i<nums.size(); ++i )
  {
    cur.push_back(nums.at(i));
    subsetiter(nums,subLen,i+1,res,cur);
    cur.pop_back();
  }
}

vector<vector<int> > subsets( vector<int>& nums ) 
{
  std::sort(nums.begin(), nums.end());
  vector<vector<int> > res;
  vector<int> cur;
  for(int len=1;len<=nums.size();++len)
  {
    subsetiter( nums, len, 0, res, cur );
    
  }
  res.push_back(vector<int> () );
  return res;
}

int main(int argc,char *argv[])
{

  vector<int> nums={0,1,2};
  vector< vector<int> > res;


  struct  timeval    tv1,tv2;
  struct  timezone   tz;
  int time1 = gettimeofday(&tv1,&tz);

  res = subsets(nums);

  int time2 = gettimeofday(&tv2,&tz);
  cout << "time consuming(local machine/leetcode server):"<<endl
    <<"leetcode server time consuming should be less than 500ms"<<endl
    << tv2.tv_usec - tv1.tv_usec <<"us/"<<0.11*( tv2.tv_usec - tv1.tv_usec )<<"ms"<< endl;

 for(auto o : res)
  {
    for(auto i : o)
    {
      cout<< i<<",";

    }
    cout<<endl;
  }



  return 0;
}
